import { TeamManager } from '../../core/TeamManager';
import { SkillEquipManager } from '../../core/SkillEquipManager';
import { FormationType } from '../../types';
import { Team } from '../../types/battle';
import { ZhaoYun, SimaYi,ZhuGeLiang,ZhouYu,HuangGai,ZhangLiao } from '../../models/generals/';
import { WangSiXiangZhu } from '../../skills/passive/WangSiXiangZhu';
import { ShenSu } from '../../skills/passive/ShenSu';
import { RuiBuKeDang } from '../../skills/active/RuiBuKeDang';

interface TeamsResult {
  teamA: Team;
  teamB: Team;
}

export function createTeams(teamManager: TeamManager, skillManager: SkillEquipManager): TeamsResult | null {
  try {
    // 创建第一队武将
    const zhaoYun = new ZhaoYun();
    const simaYi = new SimaYi();
    const zhuGeLiang = new ZhuGeLiang();

    // 设置位置
    zhaoYun.position = 0;  // 前排
    simaYi.position = 4;   // 后排
    zhuGeLiang.position = 5; // 后排

    // 装备额外技能
    skillManager.equipSkill(zhaoYun, new WangSiXiangZhu());
    skillManager.equipSkill(simaYi, new ShenSu());
    skillManager.equipSkill(zhuGeLiang, new RuiBuKeDang());

    // 创建第二队武将
    const zhouYu = new ZhouYu();
    const huangGai = new HuangGai();
    const zhangLiao = new ZhangLiao();

    // 设置位置
    zhouYu.position = 0;   // 前排
    huangGai.position = 1; // 前排
    zhangLiao.position = 4; // 后排

    // 创建队伍
    const teamA = teamManager.createTeam('teamA', [zhaoYun, simaYi, zhuGeLiang], FormationType.JI_XING);
    const teamB = teamManager.createTeam('teamB', [zhouYu, huangGai, zhangLiao], FormationType.YAN_XING);

    if (!teamA || !teamB) {
      throw new Error('Failed to create teams');
    }

    return { teamA, teamB };
  } catch (error) {
    console.error('Error creating teams:', error);
    return null;
  }
}
